﻿//202.快乐数
class Solution {
public:
    int quadratic_sum(int n) {
        int sum = 0;
        while (n != 0) {
            sum += (n % 10) * (n % 10);
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow = n, fast = n;
        while (1) {
            slow = quadratic_sum(slow);
            fast = quadratic_sum(quadratic_sum(fast));
            if (slow == fast) {
                if (slow == 1) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }
    }
};